

from driver import get_logger
from driver import device_manager,DeviceInterface
from driver.device.zebra_printer_device import ZebraPrinterDevice

logger = get_logger("driverServer")

class PrintServer(object):
    """打印服务类"""

    def __init__(self):
        try:
            self.device:ZebraPrinterDevice = device_manager.get_device("zebra_printer")
            self.device.initialize()
            self.device.connect()
        except Exception as e:
            logger.error("PrintServer init error:{error}".format(error=e))



    def test_func(self):
        """测试函数"""

        print("=== 测试通过ID生成文本、条码和二维码功能 ===")
        # 测试通过ID生成文本
        try:

            status = self.device.get_device_status()
            print("device status:",status)

            # status = self.device.pause()
            # print("device status:",status)

            # 获取标签
            labelstr =  self.device.printer_generator.generate_text_by_id("text_label_default")
            print("labelstr:",labelstr)


            # # 测试通过ID生成文本
            # print("\n1. 测试通过ID生成文本:")
            # print_text = self.device.print_text(data="label_id_1")

            # print("print text: ",print_text)

            # print("\n2. 测试通过ID生成条码:")
            # print_barcode = self.device.print_qrcode(data="1234567890",confirm_print=True,confirm_print_timeout=10)
            # # print_barcode = device.print_barcode(data="1234567890")
            # print("print_bar:",print_barcode)

            # print("\n3. 测试通过ID生成二维码:")
            # print_rqcode = self.device.print_qrcode(data="label_id_1")
            # print("print_qrcode:",print_rqcode)

        except Exception as e:
            print(f"打印失败: {e}")


